'use strict';

angular.module('app')
    .controller('registerUserController', [ '$rootScope', '$scope', '$http', '$state',
        function($rootScope, $scope, $http, $state) {
            $scope.title = '用户列表';
            $scope.searchParams = {  };
            $scope.loading = false;

            $scope.search = function () {
                $scope.searchParams.regStartTime  = $("#regStartTime").val();
                $scope.searchParams.regEndTime  = $("#regEndTime").val();
                $scope.searchParams.logOutStartTime  = $("#logOutStartTime").val();
                $scope.searchParams.logOutEndTime  = $("#logOutEndTime").val();
                $scope.loading = true;
                console.log($scope.searchParams);
                $.ajax({
                    url : $scope.app.project_name+'/registerUser/list',
                    data: $scope.searchParams
                }).then(function(result) {
                    $scope.loading = false;
                    if (result.httpCode == 200) {
                        $scope.pageInfo = result.data;
                    } else {
                        $scope.msg = result.msg;
                    }
                    $scope.$apply();
                });
            }


            $scope.searchRe = function () {
                $scope.searchParams.regStartTime  = $("#regStartTime").val();
                $scope.searchParams.regEndTime  = $("#regEndTime").val();
                $scope.searchParams.logOutStartTime  = $("#logOutStartTime").val();
                $scope.searchParams.logOutEndTime  = $("#logOutEndTime").val();
                $scope.searchParams.pageNum = 1;
                $scope.loading = true;
                console.log($scope.searchParams);
                $.ajax({
                    url : $scope.app.project_name+'/registerUser/list',
                    data: $scope.searchParams
                }).then(function(result) {
                    $scope.loading = false;
                    if (result.httpCode == 200) {
                        $scope.pageInfo = result.data;
                    } else {
                        $scope.msg = result.msg;
                    }
                    $scope.$apply();
                });
            }

            $scope.search();

            $scope.clearSearch = function() {
                $("#regStartTime").val("");
                $("#regEndTime").val("");
                $("#logOutStartTime").val("");
                $("#logOutEndTime").val("");
                $scope.searchParams= {};
                $scope.search();
            }

            $scope.resetPassword= function (userID) {
                $scope.alertMessage({
                    text:"确定做此操作吗？", //内容
                    btnCancel:true, //取消按钮
                    btnConfirm:true //确认按钮
                }).then(function () {
                    $.ajax({
                        url : $scope.app.project_name + '/registerUser/resetPassword',
                        data: {'userID': userID}
                    }).then(function(result) {
                        $scope.loading = false;
                        if (result.httpCode == 200) {
                            alert(result.data);
                        } else {
                            $scope.msg = result.msg;
                        }
                    });
                })
            }

            // 翻页
            $scope.pagination = function (pageNo) {
                $scope.searchParams.pageNum=pageNo;
                $scope.search();
            };
        } ]);